package com.situ.mall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.mall.pojo.entity.product.Collect;
import com.situ.mall.pojo.entity.product.Product;
import com.situ.mall.product.mapper.CollectMapper;
import com.situ.mall.product.mapper.ProductMapper;
import com.situ.mall.product.service.ICollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Sun Huijuan
 * @since 2024-10-17
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements ICollectService {
	@Autowired
	private CollectMapper collectMapper;
	@Autowired
	private ProductMapper productMapper;
	
	@Override
	public List<Product> getCollect(Long id) {
		QueryWrapper<Collect> wrapper = new QueryWrapper<>();
		wrapper.eq("user_id", id);
		List<Collect> collectList = collectMapper.selectList(wrapper);
		List<Product> productList = new ArrayList<>();
		for (Collect collect : collectList) {
			Product product=productMapper.selectById(collect.getProductId());
			productList.add(product);
		}
		return productList;
	}
}
